package com.javakc.pms.instruction.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.javakc.pms.instruction.entity.Instruction;
import com.javakc.pms.instruction.service.InstructionService;
import com.javakc.pms.instruction.vo.InstructionData;
import org.springframework.beans.BeanUtils;

public class ExcelListener extends AnalysisEventListener<InstructionData> {

    private InstructionService instructionService;

    public ExcelListener(){

    }

    public ExcelListener(InstructionService instructionService){
        this.instructionService =instructionService;
    }

    public void invoke(InstructionData data, AnalysisContext context){
        // 创建 Instruction 实体
        Instruction instruction = new Instruction();
        BeanUtils.copyProperties(data,instruction);
        // 保存
        instructionService.save(instruction);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
